home *** CD-ROM | disk | FTP | other *** search
- class Heroes.HeavyEllipticalCylinder extends Heroes.WorldObject
- {
- var hasBeenBumped;
- var xr;
- var zr;
- var zMax;
- var zMin;
- var bounds_mc;
- var x;
- var isRectangle;
- var prevX;
- var prevZ;
- var z;
- var collisionSounds;
- var lastCollisionSoundTime;
- var lastCollisionSoundNumber;
- function HeavyEllipticalCylinder()
- {
- super();
- this.hasBeenBumped = false;
- if(this.xr == -1)
- {
- this.xr = this._width * 0.5;
- }
- if(this.zr == -1)
- {
- this.zr = this._width * 0.5;
- }
- this.zMax = 450;
- this.zMin = -200;
- if(this.bounds_mc != null)
- {
- this.bounds_mc._visible = false;
- this.xr = this.bounds_mc._width / 2.4;
- this.zr = this.bounds_mc._height / 2;
- }
- this.xr += Heroes.Player.boundBoxWidth / 2;
- this.zr += Heroes.Player.boundBoxDepth / 2;
- }
- function onEnterFrame()
- {
- if(super.isOnScreen())
- {
- this._visible = true;
- var _loc3_ = this.x - this._parent.player.x;
- if(Math.abs(_loc3_) <= this.xr)
- {
- if(this.isRectangle == true)
- {
- this.rectangleCollisionDetection();
- }
- else
- {
- this.ellipseCollisionDetection();
- }
- }
- super.onEnterFrame();
- this.prevX = this.x;
- this.prevZ = this.x;
- }
- else
- {
- this.hasBeenBumped = false;
- this._visible = false;
- }
- }
- function ellipseCollisionDetection_old()
- {
- var _loc3_ = this.x - this._parent.player.x;
- var _loc2_ = this.z - this._parent.player.z;
- var _loc12_ = _loc3_ / this.xr;
- var _loc9_ = _loc2_ / this.zr;
- var _loc10_ = Math.pow(_loc12_,2) + Math.pow(_loc9_,2);
- if(_loc10_ <= 1)
- {
- this.hasBeenBumped = true;
- var _loc4_ = Math.sqrt(Math.pow(_loc3_,2) + Math.pow(_loc2_,2));
- this._parent.player.z -= 3 * _loc2_ / _loc4_;
- this._parent.player.x -= 3 * _loc3_ / _loc4_;
- var _loc11_ = this.x - this._parent.player.prevX;
- var _loc8_ = this.z - this._parent.player.prevZ;
- var _loc5_ = _loc11_ / this.xr;
- var _loc6_ = _loc8_ / this.zr;
- var _loc7_ = Math.sqrt(Math.pow(_loc5_,2) + Math.pow(_loc6_,2));
- this._parent.player.z = this.z - _loc6_ * this.zr / _loc7_;
- this._parent.player.x = this.x - _loc5_ * this.xr / _loc7_;
- }
- }
- function ellipseCollisionDetection()
- {
- var _loc11_ = this.x - this._parent.player.x;
- var _loc10_ = this.z - this._parent.player.z;
- var _loc3_ = _loc11_ / this.xr;
- var _loc5_ = _loc10_ / this.zr;
- var _loc12_ = Math.pow(_loc5_,2) + Math.pow(_loc3_,2);
- if(_loc12_ <= 1)
- {
- this.hasBeenBumped = true;
- var _loc4_ = (this.x - this._parent.player.prevX) / this.xr;
- var _loc2_ = (this.z - this._parent.player.prevZ) / this.zr;
- var _loc9_ = _loc4_ * _loc3_ + _loc2_ * _loc5_;
- if(_loc9_ < 0)
- {
- trace("Player Crossed the center");
- _loc5_ = _loc2_;
- _loc3_ = _loc4_;
- }
- var _loc6_ = _loc4_ + (_loc3_ - _loc4_) * 0.5;
- var _loc8_ = _loc2_ + (_loc5_ - _loc2_) * 0.5;
- var _loc7_ = Math.sqrt(Math.pow(_loc6_,2) + Math.pow(_loc8_,2));
- this._parent.player.z = this.z - _loc8_ * this.zr / _loc7_;
- this._parent.player.x = this.x - _loc6_ * this.xr / _loc7_;
- this.playCollisionSound();
- }
- }
- function rectangleCollisionDetection()
- {
- var _loc5_ = this.x - this._parent.player.x;
- var _loc4_ = this.z - this._parent.player.z;
- if(Math.abs(_loc5_) <= this.xr && Math.abs(_loc4_) <= this.zr)
- {
- var _loc7_ = this.x - this._parent.player.prevX;
- var _loc6_ = this.z - this._parent.player.prevZ;
- var _loc3_ = this._parent.player.x;
- var _loc2_ = this._parent.player.z;
- if(_loc7_ <= - this.xr)
- {
- _loc3_ = Math.max(this.x + this.xr + 1,this._parent.player.x);
- }
- if(_loc7_ >= this.xr)
- {
- _loc3_ = Math.min(this.x - this.xr - 1,this._parent.player.x);
- }
- if(_loc6_ <= - this.zr)
- {
- _loc2_ = Math.max(this.z + this.zr + 1,this._parent.player.z);
- }
- if(_loc6_ >= this.zr)
- {
- _loc2_ = Math.min(this.z - this.zr - 1,this._parent.player.z);
- }
- _loc5_ = this.x - _loc3_;
- _loc4_ = this.z - _loc2_;
- if(Math.abs(_loc5_) <= this.xr && Math.abs(_loc4_) <= this.zr)
- {
- if(Math.abs(_loc5_) <= this.xr)
- {
- if(_loc7_ < 0)
- {
- _loc3_ = Math.max(this.x + this.xr + 1,this._parent.player.x);
- }
- if(_loc7_ >= 0)
- {
- _loc3_ = Math.min(this.x - this.xr - 1,this._parent.player.x);
- }
- }
- if(Math.abs(_loc4_) <= this.zr)
- {
- if(_loc6_ < 0)
- {
- _loc2_ = Math.max(this.z + this.zr + 1,this._parent.player.z);
- }
- if(_loc6_ >= 0)
- {
- _loc2_ = Math.min(this.z - this.zr - 1,this._parent.player.z);
- }
- }
- }
- this._parent.player.x = _loc3_;
- this._parent.player.z = _loc2_;
- this.playCollisionSound();
- }
- }
- function playCollisionSound()
- {
- if(this.collisionSounds != null && this.collisionSounds.length > 0)
- {
- var _loc4_ = [6.5,4,3];
- var _loc2_ = _loc4_[Math.min(this.collisionSounds.length - 1,3)] * 1000;
- if(this.lastCollisionSoundTime == null)
- {
- this.lastCollisionSoundTime = - _loc2_;
- }
- var _loc3_ = getTimer() - this.lastCollisionSoundTime;
- if(_loc3_ > _loc2_)
- {
- this.lastCollisionSoundTime = getTimer();
- if(this.lastCollisionSoundNumber == null)
- {
- this.lastCollisionSoundNumber = 0;
- }
- else
- {
- this.lastCollisionSoundNumber = this.lastCollisionSoundNumber + 1;
- }
- if(this.lastCollisionSoundNumber >= this.collisionSounds.length)
- {
- this.lastCollisionSoundNumber = 0;
- }
- this.playSound(this.collisionSounds[this.lastCollisionSoundNumber]);
- }
- }
- }
- }
-